/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import React from 'react';
import { View, Text, Image, StyleSheet, ImageBackground, TouchableOpacity } from 'react-native';
import { useBreakpointValue } from '@hadss/react_native_adaptive_layout';

const PlaylistHeader: React.FC<{ changePage: (value: React.SetStateAction<string>) => void; songsLength: number }> = (props) => {
  const { changePage, songsLength } = props;

  const imageNumber = '3456万';
  const playlistTitle = '轻快旋律：这里是疲倦灵魂栖息地';
  const playlistDescription = '怀旧使我快乐，人们总是以为自己的生活很枯燥/乏味，那是因为他们没有回过头来聆听那些曾陪伴过我们青春的旋律';

  const fourImages = [
    require('../../../../assets/playList/love_count.png'),
    require('../../../../assets/playList/download_count.png'),
    require('../../../../assets/playList/commen_count.png'),
    require('../../../../assets/playList/share.png'),
  ];

  let paddingHorizontal = useBreakpointValue({
    base: 16,
    sm: 16,
    md: 113,
  });

  let listHeaderImage = useBreakpointValue({
    base: 16,
    sm: 16,
    md: 24,
    lg: 24,
    xl: 24,
  });

  return (
    <View style={{ width: '100%', height: 330 }}>
      <ImageBackground source={require('../../../../assets/playList/header_background.png')} resizeMode="cover">
        <TouchableOpacity
          onPress={(): void => {
            changePage('Home');
          }}>
          <Image source={require('../../../../assets/playList/back.png')} style={styles.backButton} />
        </TouchableOpacity>
        <View style={[styles.playlistInfo, { paddingHorizontal: paddingHorizontal }]}>
          <View style={styles.imageWrapper}>
            <Image source={require('../../../../assets/playList/cover.png')} style={styles.playlistImage} />
            <View style={styles.imageOverlay}>
              <Text style={styles.imageNumber}>{imageNumber}</Text>
            </View>
          </View>
          <View style={styles.playlistText}>
            <Text style={styles.textTitle}>{playlistTitle}</Text>
            <Text style={styles.textDescription} numberOfLines={1} ellipsizeMode="tail">
              {playlistDescription}
            </Text>
            <Text style={styles.author}>{'Christopher'}</Text>
          </View>
        </View>

        <View style={[styles.imagesRow, { paddingHorizontal: paddingHorizontal }]}>
          {fourImages.map((image, index) => (
            <Image key={index} source={image} style={styles.fourImage} />
          ))}
        </View>
      </ImageBackground>
      <View style={[styles.listHeader, , { paddingHorizontal: listHeaderImage }]}>
        <Image source={require('../../../../assets/playList/play_icon.png')} style={styles.listHeaderImage} />
        <Text style={styles.listHeaderText}>{'播放全部'}</Text>
        <Text style={styles.listHeaderText}>{songsLength}</Text>
        <View style={styles.flexStyle} />
        <Image source={require('../../../../assets/playList/show_all.png')} style={styles.openIcon} />
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  backButton: {
    marginTop: 24,
    marginLeft: 16,
    width: 40,
    height: 40,
  },
  playlistInfo: {
    flexDirection: 'row',
    marginTop: 8,
    height: 120,
  },
  imageWrapper: {
    position: 'relative',
    marginRight: 15,
  },
  playlistImage: {
    width: 112,
    height: 112,
  },
  imageOverlay: {
    position: 'absolute',
    bottom: 12,
    left: 6,
  },
  imageNumber: {
    color: 'rgba(255, 255, 255, 0.86)',
    fontSize: 12,
  },
  playlistText: {
    flex: 1,
    justifyContent: 'center',
  },
  textTitle: {
    fontSize: 24,
    fontWeight: '700',
    color: 'rgba(255, 255, 255, 0.86)',
  },
  textDescription: {
    marginTop: 8,
    fontSize: 12,
    color: 'rgba(255, 255, 255, 0.6)',
    width: 200,
  },
  author: {
    marginTop: 7,
    fontSize: 14,
    color: 'rgba(255, 255, 255, 0.6)',
  },
  imagesRow: {
    flexDirection: 'row',
    marginTop: 12,
    justifyContent: 'space-between',
    marginBottom: 32,
  },
  fourImage: {
    width: 48,
    height: 48,
  },
  listHeader: {
    height: 48,
    flexDirection: 'row',
    alignItems: 'center',
    width: '100%',
  },
  listHeaderImage: {
    width: 32,
    height: 32,
  },
  listHeaderText: {
    left: 8,
    fontSize: 18,
    color: 'rgba(0, 0, 0, 0.9)',
    fontWeight: '700',
    lineHeight: 24,
    marginRight: 6,
  },
  openIcon: {
    width: 20,
    height: 20,
    right: 8,
  },
  flexStyle: {
    flex: 1,
  },
});

export default PlaylistHeader;
